<template>
	<view class="login">
		<view class="title">
			西瓜记账
		</view>
		<view class="content">
			<view class="input">
				<uni-icons type="person" size="30"></uni-icons>
				<input type="number" v-model="form.nickName" placeholder="请输入昵称" maxlength="11" name="" id=""
					value="" />
			</view>
			<view class="input">
				<uni-icons type="person" size="30"></uni-icons>
				<input type="number" v-model="form.username" placeholder="请输入手机号" maxlength="11" name="" id=""
					value="" />
			</view>
			<view class="input">
				<uni-icons type="locked" size="30"></uni-icons>
				<input type="password" v-model="form.password" placeholder="请输入密码" name="" id="" value="" />
			</view>
			<view class="input">
				<uni-icons type="refresh" size="30"></uni-icons>
				<input type="password" v-model="form.password2" placeholder="请再次输入密码" name="" id="" value="" />
			</view>
			<view class="register" @click="toLogin">
				返回登录
			</view>
			<button type="primary" @click="resigter">快速注册</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				form: {
					nickName:"",
					username: null,
					password: "",
					password2: ""
				}
			};
		},
		methods: {
			toLogin() {
				console.log("点击了返回登录");
				uni.navigateBack({
					delta: 1
				});
			},
			async resigter() {
				if (this.form.password != this.form.password2) {
					console.log("两次密码不相等");
					uni.$showMsg(" 注册失败,两次密码不相等")
				}
				console.log(this.form);
				const {
					data: res
				} = await uni.$http.post("/user/addUser", {
						username: this.form.username,
						password: this.form.password,
						nickName: this.form.nickName,
					}
				)
				if (res.code !== 0) return uni.$showMsg("注册失败,账号已存在")
				
			}
		}
	}
</script>

<style lang="scss">
	.login {
		background-color: #38A678;
		height: 100vh;
		padding: 50px 10px;
		display: flex;
		flex-direction: column;
		box-sizing: border-box;

		.title {
			font-size: 25px;
			color: #fff;
			font-weight: bold;
		}

		.content {
			margin-top: 10px;
			background-color: #fff;
			border-radius: 10px;
			box-sizing: border-box;
			padding: 10px;
			height: 300px;
			display: flex;
			flex-direction: column;
			justify-content: space-around;

			.input {
				display: flex;
				align-items: center;
				border-bottom: 1px solid #999;
			}

			.register {
				display: flex;
				justify-content: flex-end;
				color: #999;
			}

			button {
				width: 100%;
			}
		}
	}
</style>
